local skel = fk.CreateSkill {
  name = "emo__shuangfei",
}

Fk:loadTranslationTable{
  ["emo__shuangfei"] = "双飞",
  [":emo__shuangfei"] = "你或拥有“翼”的角色使用牌结算结束后，若此牌造成了伤害，另一方可以弃置一张与此牌同颜色的牌，视为对相同目标角色使用此牌。",

  ["#emo__shuangfei"] = "双飞：你可以弃置一张%arg牌，视为对相同目标角色使用【%arg2】",
  ["#emo__shuangfei-single"] = "双飞：你可以弃置一张%arg牌，视为对 %dest 使用【%arg2】",

  ["$emo__shuangfei1"] = "小女不才，愿与君双宿而双飞。",
  ["$emo__shuangfei2"] = "身有彩鳞双飞翼，落羽紫微帝王家。",
}

skel:addEffect(fk.CardUseFinished, {
  anim_type = "support",
  can_trigger = function(self, event, target, player, data)
    local room = player.room
    if player:hasSkill(skel.name) and data.card.color ~= Card.NoColor and data.damageDealt and data.tos and #data.tos > 0 then
      local other = room:getPlayerById(player:getMark("emo__biyi"))
      if other and other:isAlive() and (target == player or target == other) then
        local user = (target == player) and other or player
        local card = Fk:cloneCard(data.card.name)
        card.skillName = skel.name
        if user and not user:isNude() and not user:prohibitUse(card) then
          return table.find(data.tos, function (to)
            return not user:isProhibited(to, card) and not to.dead
          end) ~= nil
        end
      end
    end
  end,
  on_cost = function (self, event, target, player, data)
    local room = player.room
    local user = (target == player) and room:getPlayerById(player:getMark("emo__biyi")) or player
    local color = data.card:getColorString()
    local colorTosuit = { ["red"] = "heart,diamond", ["black"]="spade,club" }
    local prompt = ""
    local card = Fk:cloneCard(data.card.name)
    card.skillName = skel.name
    local tos = table.filter(data.tos, function (to)
      return not user:isProhibited(to, card) and not to.dead
    end)
    if #tos == 0 then return false end
    if #tos > 1 then
      prompt = "#emo__shuangfei:::"..color..":"..data.card.name
    else
      prompt = "#emo__shuangfei-single::".. tos[1].id .. ":"..color..":"..data.card.name
    end
    local throw = room:askToDiscard(user, {
      min_num = 1, max_num = 1, include_equip = true, cancelable = true, skill_name = skel.name, skip = true,
      prompt = prompt, pattern = ".|.|"..colorTosuit[color],
    })
    if #throw > 0 then
      event:setCostData(self, { user = user, cards = throw, use_tos = tos })
      return true
    end
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    local cost_data = event:getCostData(self)
    local user, tos, cards = cost_data.user, cost_data.use_tos, cost_data.cards
    room:throwCard(cards, self.name, user, user)
    room:useVirtualCard(data.card.name, nil, user, tos, skel.name, true)
  end,
})

return skel
